package cn.tedu.tmall.admin.mall.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
@Component
public class TimerAspect {

    @Around("execution(* cn.tedu.tmall.admin.mall.service.*.*(..))")
    public Object timer(ProceedingJoinPoint pjp) throws Throwable {
        Class<?> className = pjp.getTarget().getClass();
        String methodName = pjp.getSignature().getName();
        Object[] args = pjp.getArgs();
        System.out.println("类名：" + className);
        System.out.println("方法名：" + methodName);
        System.out.println("参数列表：" + Arrays.toString(args));

        long start = System.currentTimeMillis();
        Object result = pjp.proceed();
        long end = System.currentTimeMillis();
        System.out.println("执行耗时：" + (end - start));
        return result;
    }

}
